import axios from "axios";

const baseUrl = '/api'


class HttpRequest{
    constructor(baseUrl){
        this.baseUrl = baseUrl
    }
    getInsideConfig(){
        const config = {
            baseUrl:this.baseUrl,
            header:{}
        }
        return config
    }
    interception(){
        //  添加请求拦截器
        axios.interceptors.request.use(function (config){
            // 在发送请求之前应该做什么
            return config;
        }, function (error) {
            return Promise.reject(error);
        })
        
        // 添加响应拦截器
        axios.interceptors.response.use(function (response){
            return response;
        }, function (error) {
            return Promise.reject(error);
        
        })
        
    }
    request(options){
        options = { ...this.getInsideConfig(), ...options}
        //创建axios的示例
        const instance = axios.create()
        // 示例拦截器的绑定
        this.interception(instance)

        return instance(options)
        
    }
}
